Skip to content

Conversation

@wjyrich
Copy link
Contributor

@wjyrich wjyrich commented Aug 13, 2025

  1. Added Enable_ShowDesktop configuration in dconfig to control show desktop area visibility
  2. Implemented DConfig integration to read and monitor configuration changes
  3. Added visible property and related signals in ShowDesktop class
  4. Connected configuration changes to UI visibility updates
  5. Added shouldVisible property in QML to reflect configuration state

This change allows users to enable/disable the show desktop area through system settings while maintaining the existing functionality when enabled. The implementation uses DConfig for configuration management and properly propagates changes between backend and UI.

feat: 添加可配置的显示桌面功能

  1. 在dconfig中添加Enable_ShowDesktop配置项用于控制显示桌面区域的可见性
  2. 实现DConfig集成以读取和监控配置变更
  3. 在ShowDesktop类中添加visible属性和相关信号
  4. 将配置变更连接到UI可见性更新
  5. 在QML中添加shouldVisible属性以反映配置状态

此更改允许用户通过系统设置启用/禁用显示桌面区域,同时保留启用时的现有功
能。该实现使用DConfig进行配置管理,并正确地在后端和UI之间传播变更。

Pms: BUG-312457

Summary by Sourcery

Add a configurable Show Desktop feature by introducing a new DConfig key, wiring it into the ShowDesktop applet, and exposing its visibility state to QML.

New Features:

  • Introduce Enable_ShowDesktop config option to toggle the Show Desktop area
  • Expose ShowDesktop visibility through a new QML-accessible property

Enhancements:

  • Integrate DConfig into ShowDesktop to load initial visibility and monitor runtime config changes

Chores:

  • Add Enable_ShowDesktop entry to the dock’s DConfig JSON schema

@sourcery-ai
Copy link

sourcery-ai bot commented Aug 13, 2025

Reviewer's Guide

This PR integrates DConfig into the ShowDesktop applet to introduce an Enable_ShowDesktop configuration option, manages a new visible state in the backend, and propagates it to the QML UI with real-time updates on configuration changes.

Sequence diagram for configuration change propagation to UI visibility

sequenceDiagram
    participant DConfig
    participant ShowDesktop
    participant QML_UI
    DConfig->>ShowDesktop: valueChanged("Enable_ShowDesktop")
    ShowDesktop->>ShowDesktop: onEnableShowDesktopChanged()
    ShowDesktop->>ShowDesktop: setVisible(enabled)
    ShowDesktop-->>QML_UI: visibleChanged signal
    QML_UI->>QML_UI: shouldVisible property updated
Loading

Entity relationship diagram for new Enable_ShowDesktop config option

erDiagram
    DS_DOCK_CONFIG {
        bool Enable_ShowDesktop
    }
    DS_DOCK_CONFIG ||--o| ShowDesktop : controls visibility
Loading

Class diagram for updated ShowDesktop class with DConfig integration

classDiagram
    class ShowDesktop {
        +bool visible()
        +void setVisible(bool visible)
        +void toggleShowDesktop()
        +bool checkNeedShowDesktop()
        +void onEnableShowDesktopChanged()
        -TreelandWindowManager *m_windowManager
        -Dtk::Core::DConfig *m_dockConfig
        -bool m_visible
        <<signal>> visibleChanged
    }
    ShowDesktop --|> DApplet
    ShowDesktop o-- DConfig
    ShowDesktop o-- TreelandWindowManager
Loading

File-Level Changes

Change Details Files
Integrate DConfig to read and monitor the Enable_ShowDesktop setting
  • Instantiate DConfig in ShowDesktop constructor
  • Connect DConfig::valueChanged to onEnableShowDesktopChanged
  • Read initial Enable_ShowDesktop value in init()
showdesktop.cpp
Add visible state management and signals to ShowDesktop
  • Add m_visible member and initialize default true
  • Implement visible() getter and setVisible() setter
  • Declare Q_PROPERTY and emit visibleChanged() signal
showdesktop.h
showdesktop.cpp
Handle configuration changes by updating the visible state
  • Implement onEnableShowDesktopChanged() to read config and call setVisible()
  • Log configuration change for debugging
showdesktop.cpp
Expose configuration-based visibility to QML
  • Add shouldVisible property in showdesktop.qml
  • Bind shouldVisible to the Applet.visible backend property
showdesktop.qml
Define Enable_ShowDesktop option in the dock dconfig schema
  • Add Enable_ShowDesktop entry with default value in org.deepin.ds.dock.json
org.deepin.ds.dock.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @wjyrich - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `panels/dock/showdesktop/showdesktop.cpp:32` </location>
<code_context>
+    // 创建DConfig实例来读取dock配置
+    m_dockConfig = DConfig::create("org.deepin.dde.shell", "org.deepin.ds.dock", QString(), this);
+    
+    if (m_dockConfig) {
+        // 监听配置变化
+        connect(m_dockConfig, &DConfig::valueChanged, this, [this](const QString &key) {
+            if (key == "Enable_ShowDesktop") {
+                onEnableShowDesktopChanged();
+            }
+        });
+    }
</code_context>

<issue_to_address>
Consider handling DConfig initialization failure more explicitly.

If m_dockConfig is null, consider logging a warning or handling the failure to improve visibility and debugging of configuration issues.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    m_dockConfig = DConfig::create("org.deepin.dde.shell", "org.deepin.ds.dock", QString(), this);

    if (m_dockConfig) {
        // 监听配置变化
        connect(m_dockConfig, &DConfig::valueChanged, this, [this](const QString &key) {
            if (key == "Enable_ShowDesktop") {
                onEnableShowDesktopChanged();
            }
        });
    }
=======
    m_dockConfig = DConfig::create("org.deepin.dde.shell", "org.deepin.ds.dock", QString(), this);

    if (m_dockConfig) {
        // 监听配置变化
        connect(m_dockConfig, &DConfig::valueChanged, this, [this](const QString &key) {
            if (key == "Enable_ShowDesktop") {
                onEnableShowDesktopChanged();
            }
        });
    } else {
        qWarning() << "Failed to initialize DConfig for ShowDesktop: dock config is null.";
    }
>>>>>>> REPLACE

</suggested_fix>

### Comment 2
<location> `panels/dock/showdesktop/showdesktop.cpp:23` </location>
<code_context>
 ShowDesktop::ShowDesktop(QObject *parent)
     : DApplet(parent)
     , m_windowManager(nullptr)
</code_context>

<issue_to_address>
Consider replacing the raw DConfig pointer and separate slot with an in-place DConfig member and a single lambda to update visibility.

Consider ditching the raw `DConfig*` + validity checks + extra slot and just keep a `DConfig` member initialized in-place, read the default once, and hook one lambda to update your `m_visible`. You can collapse ctor + init into:

```cpp
// showdesktop.h
class ShowDesktop : public DApplet {
    Q_OBJECT
    Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged)
public:
    explicit ShowDesktop(QObject *parent = nullptr);

    bool visible() const { return m_visible; }
    void setVisible(bool v) {
        if (m_visible == v) return;
        m_visible = v;
        Q_EMIT visibleChanged();
    }

signals:
    void visibleChanged();

private:
    DConfig m_dockConfig{"org.deepin.dde.shell", "org.deepin.ds.dock"};
    bool    m_visible{true};
};
```

```cpp
// showdesktop.cpp
ShowDesktop::ShowDesktop(QObject *parent)
    : DApplet(parent)
    , m_visible(m_dockConfig.value("Enable_ShowDesktop", true).toBool())
{
    // One shot: emit initial state
    Q_EMIT visibleChanged();

    // Update on config change
    connect(&m_dockConfig, &DConfig::valueChanged, this, [this](const QString &key) {
        if (key == QLatin1String("Enable_ShowDesktop")) {
            setVisible(m_dockConfig.value(key, true).toBool());
        }
    });

    DApplet::init();
}
```

This:

- Removes the raw pointer + `.isValid()` guards
- Inlines the “read default” & “watch for changes” in one place
- Eliminates a separate `onEnableShowDesktopChanged()` slot  
- Keeps all existing behavior intact but cuts ~20 lines of boilerplate.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines 30 to 39
// 监听配置变化
connect(m_dockConfig, &DConfig::valueChanged, this, [this](const QString &key) {
if (key == "Enable_ShowDesktop") {
onEnableShowDesktopChanged();
}
});
}
}

bool ShowDesktop::load()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider handling DConfig initialization failure more explicitly.

If m_dockConfig is null, consider logging a warning or handling the failure to improve visibility and debugging of configuration issues.

Suggested change
m_dockConfig = DConfig::create("org.deepin.dde.shell", "org.deepin.ds.dock", QString(), this);
if (m_dockConfig) {
// 监听配置变化
connect(m_dockConfig, &DConfig::valueChanged, this, [this](const QString &key) {
if (key == "Enable_ShowDesktop") {
onEnableShowDesktopChanged();
}
});
}
m_dockConfig = DConfig::create("org.deepin.dde.shell", "org.deepin.ds.dock", QString(), this);
if (m_dockConfig) {
// 监听配置变化
connect(m_dockConfig, &DConfig::valueChanged, this, [this](const QString &key) {
if (key == "Enable_ShowDesktop") {
onEnableShowDesktopChanged();
}
});
} else {
qWarning() << "Failed to initialize DConfig for ShowDesktop: dock config is null.";
}

ShowDesktop::ShowDesktop(QObject *parent)
: DApplet(parent)
, m_windowManager(nullptr)
, m_dockConfig(nullptr)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider replacing the raw DConfig pointer and separate slot with an in-place DConfig member and a single lambda to update visibility.

Consider ditching the raw DConfig* + validity checks + extra slot and just keep a DConfig member initialized in-place, read the default once, and hook one lambda to update your m_visible. You can collapse ctor + init into:

// showdesktop.h
class ShowDesktop : public DApplet {
    Q_OBJECT
    Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged)
public:
    explicit ShowDesktop(QObject *parent = nullptr);

    bool visible() const { return m_visible; }
    void setVisible(bool v) {
        if (m_visible == v) return;
        m_visible = v;
        Q_EMIT visibleChanged();
    }

signals:
    void visibleChanged();

private:
    DConfig m_dockConfig{"org.deepin.dde.shell", "org.deepin.ds.dock"};
    bool    m_visible{true};
};
// showdesktop.cpp
ShowDesktop::ShowDesktop(QObject *parent)
    : DApplet(parent)
    , m_visible(m_dockConfig.value("Enable_ShowDesktop", true).toBool())
{
    // One shot: emit initial state
    Q_EMIT visibleChanged();

    // Update on config change
    connect(&m_dockConfig, &DConfig::valueChanged, this, [this](const QString &key) {
        if (key == QLatin1String("Enable_ShowDesktop")) {
            setVisible(m_dockConfig.value(key, true).toBool());
        }
    });

    DApplet::init();
}

This:

  • Removes the raw pointer + .isValid() guards
  • Inlines the “read default” & “watch for changes” in one place
  • Eliminates a separate onEnableShowDesktopChanged() slot
  • Keeps all existing behavior intact but cuts ~20 lines of boilerplate.

Copy link
Member

@BLumia BLumia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wjyrich wjyrich force-pushed the fix-bug-312457 branch 2 times, most recently from 8ec4760 to 5f31464 Compare August 20, 2025 01:22
1. Added Enable_ShowDesktop configuration in dconfig to control show
desktop area visibility
2. Implemented DConfig integration to read and monitor configuration
changes
3. Added visible property and related signals in ShowDesktop class
4. Connected configuration changes to UI visibility updates
5. Added shouldVisible property in QML to reflect configuration state

This change allows users to enable/disable the show desktop area through
system settings while maintaining the existing functionality when
enabled. The implementation uses DConfig for configuration management
and properly propagates changes between backend and UI.

feat: 添加可配置的显示桌面功能

1. 在dconfig中添加Enable_ShowDesktop配置项用于控制显示桌面区域的可见性
2. 实现DConfig集成以读取和监控配置变更
3. 在ShowDesktop类中添加visible属性和相关信号
4. 将配置变更连接到UI可见性更新
5. 在QML中添加shouldVisible属性以反映配置状态

此更改允许用户通过系统设置启用/禁用显示桌面区域,同时保留启用时的现有功
能。该实现使用DConfig进行配置管理,并正确地在后端和UI之间传播变更。

Pms: BUG-312457
@deepin-ci-robot
Copy link

deepin pr auto review

我对这个代码变更进行审查,主要关注语法逻辑、代码质量、性能和安全性:

语法逻辑

  1. 代码逻辑基本正确,新增的配置项"enableShowDesktop"被正确添加到配置文件中,并且实现了相应的读取和响应机制。
  2. 在showdesktop.cpp中,正确地创建了DConfig实例并监听配置变化。
  3. 可见性状态的管理逻辑合理,通过visible属性和visibleChanged信号实现了UI更新。

代码质量

  1. 代码结构清晰,遵循了Qt的信号槽机制。
  2. 使用了DConfig来管理配置,符合Deepin的架构设计。
  3. 在配置变化时进行了适当的日志记录,便于调试。

性能

  1. 使用DConfig来管理配置是高效的,它会在配置变化时自动通知,不需要轮询。
  2. 在配置初始化时设置了默认值(true),避免了未初始化的问题。
  3. 配置变化时只更新必要的UI部分,不会影响整体性能。

安全性

  1. 配置项被标记为"private",防止了外部未授权的访问。
  2. 在读取配置值时进行了有效性检查,使用了isValid()方法。
  3. 配置值的变化通过信号槽机制处理,避免了直接访问可能带来的安全问题。

改进建议

  1. 在showdesktop.cpp中,可以添加对m_dockConfig创建失败的错误处理,比如当配置文件不存在或无法读取时,应该有适当的降级处理。
  2. 可以考虑为配置项添加更多的注释,说明其用途和可能的影响,特别是在多语言环境下。
  3. 在QML文件中,shouldVisible属性的用途不够明确,建议添加注释说明其作用。
  4. 可以考虑添加配置项的验证逻辑,确保配置值始终是有效的布尔值。
  5. 在onEnableShowDesktopChanged函数中,可以添加更多的日志记录,以便追踪配置变化的原因和结果。

总体来说,这个代码变更实现了一个有用的功能,允许用户控制是否显示桌面区域,代码质量较高,实现方式合理。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, wjyrich

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@wjyrich
Copy link
Contributor Author

wjyrich commented Aug 20, 2025

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Aug 20, 2025

This pr force merged! (status: behind)

@deepin-bot deepin-bot bot merged commit c067829 into linuxdeepin:master Aug 20, 2025
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants